import type { BaiduTranslateBody } from "@/types/baidu";
import { HTTPS_BAIDU_API_URL } from '@/config/baidu/translate';

/**
 * 百度相关API接口工具
 */
export function useBaiduApi() {

    /**
     * 
     * @param {BaiduTranslateBody} body 翻译参数
     * @returns 
     */
    const httpBasicTranslate = async (body: BaiduTranslateBody) => {
        return await fetch('/translate' + HTTPS_BAIDU_API_URL, {
            method: 'POST',
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            body: JSON.stringify(body)
        })
        .then(response => response.json())
        .catch(error => error.message.json());
    }

    return {
        httpBasicTranslate
    }
}